package system_design.home.dingyi;

import system_design.home.jiekou.GoodsList;
import system_design.home.shiti.Customer;
import system_design.home.shiti.Employees;
import system_design.home.shiti.User;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2022-01-07
 * Time: 13:09
 */
public class Main {
    public  static User login(){
        System.out.println("姓名");
        Scanner input = new Scanner(System.in);
        String name= input.next();
        System.out.println("请输入密码");
        int index = 3;
        while(true) {
            String password = input.next();
            if (password.equals("123")) {
                System.out.println("密码输入正确");
                break;
            } else {
                index --;
                System.out.println("密码输入错误，还有" + index+"次机会");
                if(index == 0) {
                    System.exit(0);
                }
            }
        }
        System.out.println("请输入身份 1 -> 管理员 0-> 普通成员");
        int choice = input.nextInt();
        if(choice == 1)
            return new Employees(name);//管理员类
        if(choice == 0)
            return  new Customer(name);//客户类
        return null;
    }

    public static void main(String[] args) {
        GoodsList goodsList = new GoodsList();
        User user = login();//会引用那个对象取决于你返回的对象  向上转型 *** 进入logic方法
        while(true) {//直到用户想退出为止
            int choice = user.menu();//动态绑定 选择列表
            //根据你 的选择 调用合适的操作
            user.doWork(choice, goodsList); //*** 进入各个选择操作
        }
    }
}
